# Python 2.6.4
# Project Euler, Problem 129
# Copyright 2010 Talha Zaman

def A(n):
    if (n%10) not in [1, 3, 7, 9]: return 0
    last, digit, num = n%10, 0, 0
    while True:
        num = n*table[last,(11-num%10)%10] + num
        while num%10 == 1: num, digit = num/10, digit+1
        if num == 0: break
    return digit
table = dict()
for i in [1, 3, 7, 9]:
    for j in range(10):
        table[i,(i*j)%10] = j
n = 1000001
while A(n) < 1000000: n+=2
print n
